//
//  HJJLeftViewController.m
//  Pianke
//
//  Created by 黄俊杰 on 15/12/22.
//  Copyright © 2015年 dada. All rights reserved.
//

#import "HJJLeftViewController.h"
#import "DDMenuController.h"
#import "AppDelegate.h"
#import "HJJRadioViewController.h"
#import "HJJReadViewController.h"
#import "HJJBaseNavigationController.h"
#import "PageViewController.h"
#import "HJJSettingViewController.h"
#import "HJJShopViewController.h"
#import "HJJVideoViewController.h"
#import "HJJSmallPlayerView.h"
#import "HJJPlayerViewController.h"
#import "WWYSearchViewController.h"

@interface HJJLeftViewController ()<UITableViewDataSource,UITableViewDelegate, SmallPlayerViewDelegate>
@property (nonatomic,retain)UIButton *searchButton;

@end

@implementation HJJLeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 375 * EACH_WIDTH, 600 * EACH_HEIGHT) style:UITableViewStylePlain];
    tableView.backgroundColor = [UIColor lightGrayColor];
    tableView.dataSource = self;
    tableView.delegate = self;
    
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.scrollEnabled = NO;
    [self.view addSubview:tableView];
    
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"leftCell"];
    
    [HJJSmallPlayerView shareSmallPlayerView].smallViewDele = self;
    [self.view addSubview:[HJJSmallPlayerView shareSmallPlayerView]];
    
    
}
//协议方法
-(void)musicAction{

    [HJJPlayerViewController sharePlayerViewController].outKey = 1;
    [self presentViewController:[HJJPlayerViewController sharePlayerViewController] animated:1 completion:^{
        
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"leftCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = @"  首页";
            cell.imageView.image = [UIImage imageNamed:@"main"];
            break;
        case 1:
            cell.textLabel.text = @"  电台";
            cell.imageView.image = [UIImage imageNamed:@"radio_station"];
            break;
        case 2:
            cell.textLabel.text = @"  阅读";
            cell.imageView.image = [UIImage imageNamed:@"read"];
            break;
        case 3:
            cell.textLabel.text = @"  良品";
            cell.imageView.image = [UIImage imageNamed:@"shop"];
            break;
        case 4:
            cell.textLabel.text = @"  视频";
            cell.imageView.image = [UIImage imageNamed:@"video"];
            break;
        case 5:
            cell.textLabel.text = @"  设置";
            cell.imageView.image = [UIImage imageNamed:@"setting"];
            break;
            
        default:
            break;
    }
    cell.backgroundColor = [UIColor lightGrayColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.font = [UIFont systemFontOfSize:20.0 * EACH_HEIGHT];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70 * EACH_HEIGHT;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 100 * EACH_HEIGHT;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375 * EACH_WIDTH, 100 * EACH_HEIGHT)];
#warning 修改背景图片
    headView.backgroundColor = [UIColor colorWithRed:0.12 green:0.14 blue:0.16 alpha:1];
    
    UIView *colorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375 * EACH_WIDTH, 100 * EACH_HEIGHT)];
    CGFloat colorNumber;
    for (double i = 0; i < EACH_HEIGHT * 375 ; i++) {
        colorNumber = i / (EACH_HEIGHT * 375);
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(i, 0, 1, 100 * EACH_HEIGHT)];
        view.backgroundColor = [UIColor colorWithRed:colorNumber green:colorNumber blue:colorNumber alpha:colorNumber];
        [colorView addSubview:view];
    }
    
    
    self.searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.searchButton.frame = CGRectMake(30 * EACH_WIDTH, 40 * EACH_HEIGHT, 200 * EACH_WIDTH, 30 * EACH_HEIGHT);
    
    UIImage *image = [UIImage imageNamed:@"黑色个性界面设计PSD素材_lanrentuku.com"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self.searchButton setImage:image forState:UIControlStateNormal];
    
    [self.searchButton addTarget:self action:@selector(searchAction) forControlEvents:UIControlEventTouchUpInside];
    self.searchButton.layer.masksToBounds = YES;
    self.searchButton.layer.cornerRadius = 15 * EACH_HEIGHT;
    [headView addSubview:self.searchButton];
    return headView;
    
    
}
- (void)searchAction{
//    SearchController *searchVC = [[SearchController alloc] init];
//    BaseNavigationController *searchNaVC = [[BaseNavigationController alloc] initWithRootViewController:searchVC];
//    [searchVC release
//     ];
//    [self presentViewController:searchNaVC animated:YES completion:^{
//        
//        
//    }];
    WWYSearchViewController *heheda = [[WWYSearchViewController alloc] init];
    UINavigationController *hehe = [[UINavigationController alloc] initWithRootViewController:heheda];

    [self presentViewController:hehe animated:YES completion:^{
    }];
    
    NSLog(@"搜索");
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    DDMenuController *menuController = (DDMenuController *)appDelegate.menuController;
    
    if (indexPath.row == 0) {
        PageViewController *pageVC = [[PageViewController alloc] init];
        pageVC.navigationItem.title = @"首页";
        HJJBaseNavigationController *pageNaVC = [[HJJBaseNavigationController alloc] initWithRootViewController:pageVC];
        pageNaVC.navigationBar.tintColor = [UIColor lightGrayColor];
        [menuController setRootController:pageNaVC animated:YES];
        
        
    }else if (indexPath.row == 1){
        HJJRadioViewController *radioRootVC = [[HJJRadioViewController alloc] init];
        radioRootVC.navigationItem.title = @"电台";
        HJJBaseNavigationController *radioRootNaVC = [[HJJBaseNavigationController alloc] initWithRootViewController:radioRootVC];
        radioRootNaVC.navigationBar.tintColor = [UIColor lightGrayColor];
        [radioRootNaVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"beijingyanse"] forBarMetrics:UIBarMetricsDefault];
        [menuController setRootController:radioRootNaVC animated:YES];
    }else if (indexPath.row == 2){
        HJJReadViewController *readRootVC = [[HJJReadViewController alloc] init];
        readRootVC.navigationItem.title = @"阅读";
        HJJBaseNavigationController *readRootNaVC = [[HJJBaseNavigationController alloc] initWithRootViewController:readRootVC];
        [menuController setRootController:readRootNaVC animated:YES];
        
    }else if (indexPath.row == 3){
        
        HJJShopViewController *shopRootVC = [[HJJShopViewController alloc] init];
        shopRootVC.navigationItem.title = @"良品";
        HJJBaseNavigationController *shopRootNaVC = [[HJJBaseNavigationController alloc] initWithRootViewController:shopRootVC];
        
        shopRootNaVC.navigationBar.tintColor = [UIColor lightGrayColor];
        [menuController setRootController:shopRootNaVC animated:YES];
        
    }else if (indexPath.row == 4){
        
        HJJVideoViewController *videoRootVC = [[HJJVideoViewController alloc] init];
        videoRootVC.navigationItem.title = @"视频";
        HJJBaseNavigationController *videoRootNaVC = [[HJJBaseNavigationController alloc] initWithRootViewController:videoRootVC];
        
        videoRootNaVC.navigationBar.tintColor = [UIColor lightGrayColor];
        
        [menuController setRootController:videoRootNaVC animated:YES];
    }
    else if (indexPath.row == 5){
        
        HJJSettingViewController *settingRootVC = [[HJJSettingViewController alloc] init];
        settingRootVC.navigationItem.title = @"设置";
        HJJBaseNavigationController *settingRootNaVC = [[HJJBaseNavigationController alloc] initWithRootViewController:settingRootVC];
        
        settingRootNaVC.navigationBar.tintColor = [UIColor lightGrayColor];
        [menuController setRootController:settingRootNaVC animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
